<template>
    <div class="view">
      <Panel :title="title">
        <el-form label-position="top">
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="课程名称">
            <el-input v-model="course.name" placeholder="课程名称"></el-input>
          </el-form-item>
          </el-col>
        <el-col :span="6">
      <el-form-item label="状态">
    <el-switch
      v-model="course.visible"
        active-text=""
      inactive-text="">
      </el-switch>
 </el-form-item>
</el-col>
<el-col :span="24">
  <el-form-item label="课程简介">
    <Simditor v-model="coursedescription"></Simditor>
    </el-form-item>
    </el-col>

    <el-col :span="24">
  <el-form-item label="教学目标">
    <Simditor v-model="coursedescription"></Simditor>
    </el-form-item>
    </el-col>

    <el-col :span="24">
  <el-form-item label="内容概览">
    <Simditor v-model="coursedescription"></Simditor>
    </el-form-item>
    </el-col>

    <el-col :span="24">
  <el-form-item label="参考资料">
    <Simditor v-model="coursedescription"></Simditor>
    </el-form-item>
    </el-col>
  </el-row>
</el-form>
<save click.native="saveCourse"></save>


      <p>添加和编辑课程页面需要我们自己写啦~</p>
    </Panel>
  </div>
</template>

<script>
import api from '../../api.js'
// Simditor是写好的编辑栏组件，我们可以直接引入使用
import Simditor from '../../components/Simditor.vue'

export default {
  name: 'CreateCourse',
  components: { Simditor },
  data () {
    return {
      title: '添加课程',
      course: {
        name: '',
        description: '',
        goal: '',
        content: '',
        references: '',
        visible: false
      }
    }
  },
  mounted () {
    if (this.$route.name === 'edit-course') {
      this.title = '编辑课程'
      api.getCourse(this.$route.params.courseId).then(res => {
        this.course = res.data.data
      }).catch(() => {
      })
    }
  },
  methods: {
    saveCourse () {
      let funcName = this.$route.name === 'edit-course' ? 'editCourse' : 'createCourse'
      let data = Object.assign({}, this.course)
      api[funcName](data).then(res => {
        this.$router.push({name: 'course-list', query: {refresh: 'true'}})
      }).catch((e) => {
      })
    }
  }
}
</script>
